#ifndef _BINFILE_H_
#define _BINFILE_H_

#include <stdexcept>
#include "stdlib.h"
#include <stdint.h>
#include "inicpp.h"

class BINFILE
{
public:
    BINFILE()
    {
        inicpp::IniManager Interface_ini("../config.ini");
        std::string filename = Interface_ini["file"].toString("updatefile");
        fp = fopen(filename.c_str(), "rb");
        if (fp == NULL)
        {
            throw std::runtime_error("file open error");
        }
        else
        {
            fseek(fp, 0, SEEK_END);
            m_filesize = ftell(fp);
            fseek(fp, 0, SEEK_SET);
        }
    }
    ~BINFILE()
    {
        fclose(fp);
    }
    uint32_t GetFileSize()
    {
        return m_filesize;
    }
    void ReadFile(uint8_t *buf, uint32_t bytesize)
    {
        fread(buf, sizeof(uint8_t), bytesize, fp);
        fclose(fp);
    }

private:
    FILE *fp;
    uint32_t m_filesize;
};

#endif